/* File makes Table 3 */

/* 	Input files: temp_follows, bb_counts
	Output files: T3_Follows.tex  */


**********************************************
clear all
macro drop _all
scalar drive		= "E:"
scalar maindir		= "`=drive'\Replicate"
scalar tabledir		= "`=drive'\Replicate\TablesRep"
cd "`=maindir'"
**********************************************


use temp_follows, clear  
drop bear f_bear_t1 f_bull_2_10 f_bull_11_30 f_bull_31_50 f_bull_1_10 f_bear_1_10 more*
merge 1:1 userid symbolid date using bb_counts, keep(master match) nogen 

gen countbull=bull_count-bear_count
drop bull_count bear_count

eststo t1: reghdfe f_bull_t1 bull, absorb(i.userid i.symbolid#i.date) vce(cl userid)  
	qui sum f_bull_t1 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "Y"
	cap estadd local usersymbolfE "-"

keep if e(sample)==1

eststo t1_noUfe: reghdfe f_bull_t1 bull, absorb(i.symbolid#i.date) vce(cl userid) 
	qui sum f_bull_t1 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "-"
	

drop f_bull_t1

eststo t1t5_noUfe: reghdfe f_bull_t1t5 bull, absorb(i.symbolid#i.date) vce(cl userid) 
	qui sum f_bull_t1t5 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "-"
	
eststo t1t5a: reghdfe f_bull_t1t5 bull, absorb(i.userid i.symbolid#i.date) vce(cl userid) 
	qui sum f_bull_t1t5 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "Y"
	cap estadd local usersymbolfE "-"


sum countbull, d 
gen b1m=cond(countbull<=-1,1,0)
gen b2=cond(countbull==2,1,0)
gen b3=cond(countbull==3,1,0)
gen b4=cond(countbull>=4,1,0)
drop countbull
	
eststo t1t5_dummy: reghdfe f_bull_t1t5 b1m b2 b3 b4, absorb(i.userid i.symbolid#i.date) vce(cl userid) 
	qui sum f_bull_t1t5 if e(sample)==1
	qui estadd scalar avg = r(mean)
	cap estadd local userfE "Y"
	cap estadd local usersymbolfE "-"
	
drop b1m b2 b3 b4
	
eststo t1t5b: reghdfe f_bull_t1t5 bull, absorb(i.userid#i.symbolid i.symbolid#i.date) vce(cl userid)
	qui sum f_bull_t1t5 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "Y"
	
eststo t1t5cond: reghdfe cond_f_bull_t1t5 bull , absorb(i.userid#i.symbolid i.symbolid#i.date) vce(cl userid)
	qui sum cond_f_bull_t1t5 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "Y"


drop f_bull_t1t5 cond_f_bull_t1t5

eststo t2t10cond: reghdfe cond_f_bull_2_10 bull, absorb(i.userid#i.symbolid i.symbolid#i.date) vce(cl userid)
	qui sum cond_f_bull_2_10 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "Y"

drop cond_f_bull_2_10
		
eststo t11t30cond: reghdfe cond_f_bull_11_30 bull, absorb(i.userid#i.symbolid i.symbolid#i.date) vce(cl userid)
	qui sum cond_f_bull_11_30 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "Y"

drop cond_f_bull_11_30

eststo t31t50cond: reghdfe cond_f_bull_31_50 bull, absorb(i.userid#i.symbolid i.symbolid#i.date) vce(cl userid)
	qui sum cond_f_bull_31_50 if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100
	cap estadd local userfE "-"
	cap estadd local usersymbolfE "Y"

********************************************


cap estadd local daysymbolFE "Y" : *

local stats_opts " stats(N N_clust r2 avg effect_size userfE usersymbolfE daysymbolFE, fmt(%18.0fc %18.0fc %12.2fc %12.2fc %12.0fc) labels("\# observations" "\# clusters (users)" "$\textit{R}^2$" "Mean of dependent var.($\%$)" "Effect size ($\%$ of mean)" "User FE" "User x symbol FE" "Day x symbol FE") ) " 

#delimit ; 
local opts  "b(%16.2fc) se(%16.2fc) brackets booktabs  star(* 0.10 ** 0.05 *** 0.01) nonotes lines 
mtitles(
"t+1" 
"\shortstack{\scriptsize{$+$}\\ \scriptsize{User FE} \\t+1}" 
"t+1 $\rightarrow$ t+5" 
"\shortstack{\scriptsize{$+$}\\ \scriptsize{User FE} \\t+1 $\rightarrow$ t+5}" 
"\shortstack{\scriptsize{with}\\ \scriptsize{Bull bins} \\t+1 $\rightarrow$ t+5}" 
"\shortstack{\scriptsize{$+$}\\ \scriptsize{User-Symbol FE} \\t+1 $\rightarrow$ t+5}" 
"\shortstack{\scriptsize{Conditional on} \\ \scriptsize{new follows} \\ t+1 $\rightarrow$ t+5}" 
"\shortstack{\scriptsize{Conditional on} \\ \scriptsize{new follows} \\ t+2 $\rightarrow$ t+10}" 
"\shortstack{\scriptsize{Conditional on} \\ \scriptsize{new follows} \\ t+11 $\rightarrow$ t+30}" 
"\shortstack{\scriptsize{Conditional on} \\ \scriptsize{new follows} \\ t+31 $\rightarrow$ t+50}" 
  )
mgroups("Dep. var.: $\mathbbm{1}$ x100 if new follows\textsubscript{i,s,t+x} are more Bull than Bear" 
, pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  " ;     

cd "`=tabledir'" ;
esttab t1_noUfe t1 t1t5_noUfe t1t5a t1t5_dummy t1t5b t1t5cond t2t10cond t11t30cond t31t50cond using T3_Follows.tex, `opts' `stats_opts'  keep(bull b1m b2 b3 b4) coef(
bull "$\mathbbm{1}$ Declare Bull\textsubscript{i,s,t}"
b1m "$\mathbbm{1}$ if net \# Bull declarations\textsubscript{i,s,t} $\leq$ -1"
b2  "$\mathbbm{1}$ if net \# Bull declarations\textsubscript{i,s,t} = 2"
b3  "$\mathbbm{1}$ if net \# Bull declarations\textsubscript{i,s,t} = 3"
b4  "$\mathbbm{1}$ if net \# Bull declarations\textsubscript{i,s,t} $\geq$ 4"
) replace  ;
cd "`=maindir'" ;
#delimit cr 

